package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Parking;
import com.woniuxy.service.ParkingService;
import com.woniuxy.util.PageData;
import com.woniuxy.util.RespongseData;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/parking")
@AllArgsConstructor
public class ParkingController {
    private ParkingService parkingService;

    @GetMapping("/parkingPage")
    public String parkingPage(){
        return "/parking/parking";
    }

    @PostMapping("/queryParking")
    @ResponseBody
    public RespongseData queryParking(@RequestBody PageData<Parking> pageData){
        PageInfo<Parking> parkingPageInfo = parkingService.queryParking(pageData);
        return new RespongseData(200,"ok",parkingPageInfo);
    }

    @PostMapping("/saveAddParking")
    @ResponseBody
    public RespongseData saveAddParking(@RequestBody Parking parking){
        parkingService.saveAddParking(parking);
        return new RespongseData(200,"ok",null);
    }

    @GetMapping("/updataParkingBtn/{id}")
    @ResponseBody
    public RespongseData updataParkingBtn(@PathVariable("id") Integer id){
        Parking parking = parkingService.updataParkingBtn(id);
        return new RespongseData(200,"ok",parking);
    }

    @PostMapping("/saveUpdateParking")
    @ResponseBody
    public RespongseData saveUpdateParking(@RequestBody Parking parking){
        parkingService.saveUpdateParking(parking);
        return new RespongseData(200,"ok",null);
    }

    @PostMapping("/batchDelParking")
    @ResponseBody
    public RespongseData batchDelParking(@RequestBody List<Integer> ids){
        parkingService.batchDelParking(ids);
        return new RespongseData(200,"ok",null);
    }

    @GetMapping("/delParkingBtn/{id}")
    @ResponseBody
    public RespongseData delParkingBtn(@PathVariable("id") Integer id){
        parkingService.delParkingBtn(id);
        return new RespongseData(200,"ok",null);
    }
}
